/*Copyright (c) 2020 Orca Data Technology(Xi'an)CO.LTD. All rights reserved. * Create by Jisr on 2022/3/7 10:51 AM*/
import {RenderProps, ToastId, ToastPositionWithLogical, useToast} from '@chakra-ui/react';
import {CSSProperties, ReactNode} from 'react';

export interface ToastConfig {
    containerStyle?: CSSProperties;
    description?: ReactNode;
    duration?: number | null;
    id?: ToastId;
    onCloseComplete?: () => void;
    position?: ToastPositionWithLogical;
    render?: (props: RenderProps) => ReactNode;
    status?: 'info' | 'warning' | 'success' | 'error';
    isClosable?: boolean;
}
const defaultConfig: ToastConfig = {
    isClosable: true,
    duration: 3000,
    position: 'top'
};
export interface Toast {
    error: (title: string, config?: ToastConfig) => void;
    success: (title: string, config?: ToastConfig) => void;
    warning: (title: string, config?: ToastConfig) => void;
    info: (title: string, config?: ToastConfig) => void;
}
const DefaultToast = (): Toast => {
    const toast = useToast();
    return {
        error: (title: string, config?: ToastConfig) => {
            toast({
                title: title,
                status: 'error',
                ...defaultConfig,
                ...config
            });
        },
        success: (title: string, config?: ToastConfig) => {
            toast({
                title: title,
                status: 'success',
                ...defaultConfig,
                ...config
            });
        },
        warning: (title: string, config?: ToastConfig) => {
            toast({
                title: title,
                status: 'warning',
                ...defaultConfig,
                ...config
            });
        },
        info: (title: string, config?: ToastConfig) => {
            toast({
                title: title,
                status: 'info',
                ...defaultConfig,
                ...config
            });
        }
    };
};
export default DefaultToast;
